<?php
// +----------------------------------------------------------------------------
// | Tke团队版权所属 [三十年河东三十年河西,莫欺少年穷.!]
// +----------------------------------------------------------------------------
// | Copyright (c) 2014 http://www.itdaodan.com All rights reserved.
// +----------------------------------------------------------------------------
// | Author: mahuan <mahuan@hrbjjhh.com>
// +----------------------------------------------------------------------------
namespace Admin\Model;
use Think\Model\ViewModel;
/**
 * @todo 搜索视图操作
 * @author mahuan<mahuan@hrbjjhh.com>
 * @since 2015-09-05
 */
class ServiceSearchViewModel extends ViewModel {
    protected $viewFields = array(
        'iweb_service_my_customer'=>array('customer_id','_table'=>"iweb_service_my_customer",'_type'=>'LEFT')
    );
    protected $where_array = array();
    
    /**
     * @todo 添加viewField条件
     * @access public
     * @param array $fields 文本字段
     * @return 无
     */
    private function _addField($fields){
        $this->viewFields = array_merge($this->viewFields,$fields);
        return ;
    }
    
    /**
     * @todo 返回当前状态
     * @return 状态数组
     */
    public function getStatus(){
        return array(
            'viewFields' => $this->viewFields,
            'where_array' => $this->where_array
        );
    }
    
    /**
     * @todo 返回当前状态
     * @param array $status_array 设置状态
     * @return 无
     */
    public function setStatus($status_array){
        $this->viewFields = $status_array['viewFields'];
        $this->where_array = $status_array['where_array'];
    }
    
    /**
     * @todo 添加where条件
     * @access public
     * @param array $map where条件
     * @return 无
     */
    private function _addWhere($map){
        $this->where_array = array_merge($this->where_array,$map);
        return ;
    }
    /**
     * @todo 添加条件函数
     * @access public
     * @param array $fileds 视图的字段条件
     * @param array $where 视图的where字段条件
     * @return 返回where条件数组
     */
    private function _addCondition($fileds,$where){
        $this->_addField($fileds);
        $this->_addWhere($where);
        return true;
    }
    
    /**
     * @todo 添加活动的条件
     * @param array $where 条件数组，类似where条件数组
     * @return 返回where条件数组
     */
    public function addActivityCondition($condition_array) {
        $fileds = array('iweb_service_activity_join'=>array_merge(array_keys($condition_array),array('_on'=>'iweb_service_my_customer.customer_id=iweb_service_activity_join.customer_id','_type'=>'LEFT','_table'=>"iweb_service_activity_join")));
        $this->_addCondition($fileds,$condition_array);
        return $this;
    }
    /**
     * @todo 添加装修需求的条件
     * @param array $where 条件数组，类似where条件数组
     * @return 返回where条件数组
     */
    public function addDemandCondition($condition_array) {
        $fileds = array('iweb_service_customer_demand'=>array_merge(array_keys($condition_array),array('_on'=>'iweb_service_my_customer.customer_id=iweb_service_customer_demand.customer_id','_type'=>'LEFT','_table'=>"iweb_service_customer_demand")));
        $this->_addCondition($fileds,$condition_array);
        return $this;
    }
    
    /**
     * @todo 添加房产的条件
     * @param array $where 条件数组，类似where条件数组
     * @return 返回where条件数组
     */
    public function addHouseCondition($condition_array) {
        $fileds = array('iweb_service_customer_house'=>array_merge(array_keys($condition_array),array('_on'=>'iweb_service_my_customer.customer_id=iweb_service_customer_house.customer_id','_type'=>'LEFT','_table'=>"iweb_service_customer_house")));
        $this->_addCondition($fileds,$condition_array);
        return $this;
    }
    
    /**
     * @todo 搜索
     * @return 返回结果集
     */
    public function search(){
        return $this->field('customer_id')->where($this->where_array)->select();
    }
}
